package com.lh.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lh.project.mapper.OrderMapper;
import com.lh.project.model.entity.Food;
import com.lh.project.model.entity.Order;
import com.lh.project.service.FoodService;
import com.lh.project.service.OrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
*
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order>
implements OrderService {

    @Resource
    private FoodService foodService;

    @Resource
    private OrderMapper orderMapper;

    @Override
    public List<Order> getOrderList(Long id) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_user_id",id);
        List<Order> list = list(queryWrapper);
        for(int i = 0;i < list.size();i++){
            Long foodId = list.get(i).getOrderFoodId();
            Food food = foodService.getById(foodId);
            list.get(i).setOrderImg(food.getFoodImg());
            list.get(i).setFoodName(food.getFoodName());
        }
        return list;
    }

    /**
     * 在生成账单的时候，将订单的is_delete设置为1
     * @param orderId
     */
    @Override
    public void deleteOrder(Long orderId) {
        orderMapper.deleteOrder(orderId);
    }
}
